<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>05员工表格练习</title>
</head>
<body>
<input type="text" placeholder="请输入员工姓名" id="i1">
<input type="text" placeholder="请输入员工工资" id="i2">
<input type="text" placeholder="请输入员工岗位" id="i3">
<button onclick="addEmp()">添加员工</button>
<table border="1px">
    <caption>员工表</caption>
    <tr>
        <th>姓名</th>
        <th>工资</th>
        <th>岗位</th>
    </tr>
</table>
<script>
    function addEmp(){
        //从用户那里获取值
        let uname = document.getElementById('i1').value;
        let salary = document.getElementById('i2').value;
        let job = document.getElementById('i3').value;
        //创建一个tr和三个td
        let tr = document.createElement('tr');
        let nameTd = document.createElement('td');
        let salaryTd = document.createElement('td');
        let jobTd = document.createElement('td');
        //把收集到的数据装入td中
        nameTd.innerHTML = uname;
        salaryTd.innerHTML = salary;
        jobTd.innerHTML = job;
        tr.append(nameTd,salaryTd,jobTd);
        //获取表格元素,将准备好的tr装入table中
        let table = document.querySelector('table');
        table.append(tr);
        //清空数据
        document.getElementById('i1').value="";
        document.getElementById('i2').value="";
        document.getElementById('i3').value="";
        //将收集数据存入数组
        arr.push({name:uname},{salary:salary},{job:job});
        console.log(arr);
    }
</script>
</tr>
</body>
</html>